#pragma once

#include <algorithm>
#include <string>
#include <vector>
#include <fstream>

using namespace std;

void hex_dump(fstream& fs, std::vector<_tstring>& data, long start, long end);
void hex_overwrite(fstream& fs, std::vector<_tstring>& data, long start, long end);

/*static inline*/ int hex_value(TCHAR x);
/*static inline*/ int hex_value(GString& x);
/*static inline*/ bool is_hex(_tstring x);
/*static inline*/ _tstring hex_char(int c);

#include <tchar.h>

static inline _tstring whex_char(int c)
{
	_tstring a;
	wchar_t cBuf[6];

	wprintf(cBuf, "%02X ", c&0xFF); 
	a += cBuf[0];
	a += cBuf[1];

	return a.substr(0,2);
}

//takes hex string
//returns character value of hex string
static inline unsigned char char_hex(_tstring& hex)
{
	TCHAR x = hex[0];
	TCHAR y = hex[1];
	return (unsigned char) (( 16 * hex_value(x) ) + hex_value(y));
}

static inline unsigned char char_hex(GString& hex)
{
	return char_hex((_tstring)hex);
}
